<template>
  <el-container>
    <el-aside width="200px">
      <LeftMenu></LeftMenu>
    </el-aside>
    <el-container>
      <el-header>
        <strong class="tab-control">VueAdmin</strong>
        <div class="header-avatar">
          <el-avatar size="medium" :src="userInfo.avatar"></el-avatar>
          <el-dropdown>
                      <span class="el-dropdown-link tab-control">
                        {{userInfo.username}}<i class="el-icon-arrow-down el-icon--right"></i>
                      </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <router-link to="/userCenter">
                  个人中心
                </router-link>
              </el-dropdown-item>

              <el-dropdown-item @click.native="logout">
                退出
              </el-dropdown-item>

            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <el-main>
        <Tabs></Tabs>
        <!--调用子路由 index-->
        <div style="margin: 0px 10px">
          <router-view></router-view>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
//导入组件
import LeftMenu from "./inc/LeftMenu";
import Tabs from "./inc/Tabs";
export default {
  name: "Home",
  components: {
    LeftMenu,
    Tabs
  },
  data() {
    return {
      userInfo: {
        id: "",
        username: "",
        avatar: ""
      }
    }
  },
  created() {
    this.getUserInfo()
  },
  methods: {
    getUserInfo() {
      this.$axios.get('/sys/userInfo').then(res => {
        this.userInfo = res.data.data
      })
    },
    logout() {
      /* alert(1)*/
      this.$axios.post("/logout").then(res => {
        //清空用户数据
        localStorage.clear()
        //清空用户数据
        sessionStorage.clear()
        //把存储在本地的数据清空
        this.$store.commit('resetState')
        //跳到登录页面
        this.$router.push('/login')
      })
    }
  }
}
</script>

<style scoped>
.tab-control{
  color: #FFFFFF;
}
.header-avatar {
  /*向右偏移*/
  float: right;
  width: 210px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.el-container {
  height: 100%;
}

.el-header {
  background-color: #2a384f;
  color: #2a384f;
  text-align: center;
  line-height: 60px;
}

.el-main {
  background-color: #f5f5f5;
  padding: 0;
}

.el-dropdown-link {
  cursor: pointer;
}

a {
  text-decoration: none;
}
</style>
